package nbcp.db.mongo.entity

import nbcp.db.mongo.*
import org.bson.types.ObjectId
import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.mapping.Document
import nbcp.base.comm.*
import nbcp.base.extend.AsLocalDate
import nbcp.base.extend.AsLocalDateTime
import nbcp.db.CodeName
import nbcp.db.IdName
import nbcp.db.IdUrl
import nbcp.db.IntCodeName
import nbcp.db.mongo.entity.*

import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.util.*
import javax.xml.ws.spi.http.HttpContext
import kotlin.collections.HashMap
import kotlin.collections.LinkedHashMap

/**
 * Created by udi on 17-3-19.
 */

@Document
@MongoEntityGroup("system")
data class AnnexTag(
        var tag: String = "",
        var corpId: String = ""
) : IMongoDocument() {
}


//系统附件表
@Document
@MongoEntityGroup("system")
data class SysAnnex(
        var name: String = "",          //显示的名字,友好的名称
        var ext: String = "",           //后缀名。
        var size: Int = 0,              //大小
        var checkCode: String = "",     //Md5,Sha1
        var imgWidth: Int = 0,          // 图像宽度值。
        var imgHeight: Int = 0,         // 图像宽度值。
        var url: String = "",           //下载的路径。没有 host

        var createBy: IdName = IdName(), //创建者
        var corpId: String = "",    //创建所属企业,如果是 admin,则 id = "admin" , name = "admin 即可
        var errorMsg: String = "",      //文件处理时的错误消息
        var createAt: LocalDateTime = LocalDateTime.now()
) : IMongoDocument() {
}

@Document
@MongoEntityGroup("system")
data class SysCity(
        var code: Int = 0,
        var name: String = "",
        var fullName: String = "",
        var level: Int = 0,
        var lng: Float = 0F, //经度
        var lat: Float = 0F, //纬度
        var pinyin: String = "",
        var telCode: String = "",
        var postCode: String = "",
        var pcode: Int = 0
) : IMongoDocument()


@Document
@MongoEntityGroup("system")
open class SysUser(
        var loginName: String = "",
        var name: String = "",
        var logo: IdUrl = IdUrl(), //头像.
        var mobile: String = "",
        var email: String = "",
        var birthday: LocalDate? = null,
        var sex: UserSexEnum? = null,
        var location: String = "",

        var corp: IdName = IdName(),
        var wxOpenId: String = "",
        var lastLoginAt: LocalDateTime = LocalDateTime.now(),
        var token: String = "",    //验证用户使用.
        var createAt: LocalDateTime = LocalDateTime.now(),
        var updateAt: LocalDateTime = LocalDateTime.now()
) : IMongoDocument()


@Document
@MongoEntityGroup("system")
data class SysLoginUser(
        var loginName: String = "",
        var password: String = "",
        var lastLoginAt: LocalDateTime = LocalDateTime.now(),
        var errorLoginTimes: Byte = 0,
        var isLocked: Boolean = false,
        var forget_password: Boolean = false,
        var lockedRemark: String = ""
) : IMongoDocument()

@Document
@MongoEntityGroup("system")
data class SysLoginLog(
        var loginName: String = "",
        var password: String = "", //有密码，表示登录失败
        var app: String = "", //Header 中的 App。
        var clientIp: String = "",
        var createAt: LocalDateTime = LocalDateTime.now(),
        var client: String = "",
        var remark: String = ""
) : IMongoDocument()


@Document
@MongoEntityGroup("system")
data class SysLog(
        var msg: String = "",
        var creatAt: LocalDateTime = LocalDateTime.now(),
        var createBy: String = "",
        var type: String = "",
        var clientIp: String = "",
        var module: String = "",
        var remark: String = ""
) : IMongoDocument() {
}

@Document
@MongoEntityGroup("system")
data class TraceLog(
        var traceId: String = "",
        var host: String = "",  //host_ip:port
        var type: String = "",
        var url: String = "",
        var method: String = "",
        var header: String = "",
        var body: String = "",
        var createBy: String = "",
        var createAt: LocalDateTime = LocalDateTime.now(),
        var clientIp: String = ""
) : IMongoDocument() {
}


@Document
@MongoEntityGroup("system")
data class SysCorporation(
        var name: String = "",
        var city: IntCodeName = IntCodeName(),
        var address: String = "", //企业地址
        var phone: String = "",
        var weixin: String = "",  //微信公众号
        var industry: IdName = IdName(),  //行业
        var logo: IdUrl = IdUrl(),
        var qualifications: MutableList<IdUrl> = mutableListOf(), //资质照片
        var images: MutableList<IdUrl> = mutableListOf(), //形象照片
        var detail: String = "",

        var createAt: LocalDateTime = LocalDateTime.now(),
        var updateAt: LocalDateTime = LocalDateTime.now(),
        var isLocked: Boolean = true,
        var lockedRemark: String = ""
) : IMongoDocument()

@Document
@MongoEntityGroup("system")
data class MobileCodeLog(
        var module: MobileCodeModuleEnum = MobileCodeModuleEnum.None,        //使用模块
        var mobile: String = "",
        var code: String = "",
        var bizId: String = "",          // 下发的回执Id.用它来查询状态.,有它表示发过.
        var errorMessage: String = "",  //下发的错误消息
        var isUsed: Boolean = false,    //是否已使用。
        var createAt: LocalDateTime = LocalDateTime.now(),
        var sentAt: LocalDateTime? = null,      // 下发时间
        var arrivedAt: LocalDateTime? = null,   //到达时间
        var usedAt: LocalDateTime? = null
) : IMongoDocument() {
}

@Document
@MongoEntityGroup("system")
data class MqLog(
        var name: String = "",
        var createAt: LocalDateTime = LocalDateTime.now(), //生产时间
        var arrivedAt: LocalDateTime? = null,      //到达Exchange时间
        var body: String = "",  //消息内容。
        var sendErrorMessage: String = "", //消息未到达的消息.
        var isDone: Boolean = false, //是否完成。
        var consumeAt: LocalDateTime? = null,
        var result: String = ""    //消费结果，成功为空。
) : IMongoDocument()


@Document
@MongoEntityGroup("system")
data class VersionData(
        var client: AppClientEnum = AppClientEnum.Android,
        var version: String = "",
        var remark: String = "",
        var url: IdUrl = IdUrl(),
        var mustUpdate: Boolean = false,
        var publishAt: LocalDateTime = LocalDateTime.now()
) : IMongoDocument()


@Document
@MongoEntityGroup("system")
open class NotifyMessage(
        var type: NotifyTypeEnum? = null,
        var title: String = "",
        var content: String = "",
        var isRead: Boolean = false,
        var extDbId: String = "",       //额外的数据Id , 目前对应的是 trafficLogId
        var user: IdName = IdName(),
        var isPushed: Boolean = false,
        var createAt: LocalDateTime = LocalDateTime.now(),
        var readAt: LocalDateTime = LocalDateTime.now()
) : IMongoDocument()

//用户分享日志
@Document
@MongoEntityGroup("system")
data class UserShareLog(
        var sharer: IdName = IdName(), //分享者
        var recver: IdName = IdName(), //传播者
        var url: String = "", //分享的页面
        var createAt: LocalDateTime = LocalDateTime.now()
) : IMongoDocument()


@Document
@MongoEntityGroup("system")
data class SysDictionary(
        var code: String = "",
        var value: String = "",
        var sort: Float = 0F,
        var group: SysDictionaryGroupEnum = SysDictionaryGroupEnum.Material,
        var corpId: String = ""
) : IMongoDocument()